package in.srain.cube.util.internal;

public class CodeException extends Exception {

    public final int code;

    public CodeException() {
        this.code = 0;
    }

    public CodeException(String message) {
        super(message);
        this.code = 0;
    }

    public CodeException(String message, Throwable cause) {
        super(message, cause);
        this.code = cause instanceof CodeException ? ((CodeException) cause).code : 0;
    }

    public CodeException(Throwable cause) {
        super(cause);
        this.code = cause instanceof CodeException ? ((CodeException) cause).code : 0;
    }

    public CodeException(int code) {
        this.code = code;
    }

    public CodeException(String message, int code) {
        super(message);
        this.code = code;
    }

    public CodeException(String message, Throwable cause, int code) {
        super(message, cause);
        this.code = code;
    }

    public CodeException(Throwable cause, int code) {
        super(cause);
        this.code = code;
    }

    @Override
    public String toString() {
        return '{' + super.toString() + ", code: " + code + '}';
    }
}
